/*
 * Copyright (c) 2020, chenshuai (cs4380@163.com).
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * <p>
 * https://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package com.cs.springcloud.common.biz;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.cs.springcloud.common.util.BeanUtil;
import com.cs.springcloud.common.util.EntityUtils;

/**
 * BaseBusinessBiz 基础业务类.
 * <p>
 * 新增和修改时自动添加:
 * 创建时间、创建人、更新时间、更新人
 * </p>
 *
 * @author cs
 * @version 1.0
 * @date 2018年11月29日
 */
public abstract class BaseBusinessBiz<M extends BaseMapper<T>, T> extends BaseBiz<M, T> {

    @Override
    public int insertModel(T entity) {
        BeanUtil.beanAttributeValueTrim(entity);
        EntityUtils.setCreatAndUpdatInfo(entity);
        return super.insertModel(entity);
    }

    @Override
    public int updateById(T entity) {
        BeanUtil.beanAttributeValueTrim(entity);
        EntityUtils.setUpdatedInfo(entity);
        return super.updateById(entity);
    }
}